package com.sinodata.bsm.center.service.notify;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sinodata.bsm.center.bean.Condition;
import com.sinodata.bsm.center.bean.NotifyHisBean;
import com.sinodata.bsm.center.bean.Page;
import com.sinodata.bsm.center.dao.impl.NotifyHisDaoImpl;

/**
 * <p>
 * Description: 通知历史服务类
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-25 PM 3:47:24     liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class NotifyHisService {

    @Autowired
    private NotifyHisDaoImpl notifyDao;

    /**
     * 分页查询通知历史
     * 
     * @param page
     * @param condition
     * @return
     */
    public Page<NotifyHisBean> findByPage(Page<NotifyHisBean> page, Condition condition, String dimension) {
        String resTypeId = "";
        List<String> dimensionList = new ArrayList<String>();
        if (!dimension.equals("")) {
            String[] array = dimension.split("[|]");
            for (String scope : array) {
                if (scope.split(",")[0].equals("0-资源类别")) {
                    resTypeId = scope.split(",")[1];
                } else {
                    dimensionList.add(scope.split(",")[1]);
                }
            }
        }
        return notifyDao.findByPage(page, condition, resTypeId, dimensionList);
    }

    /**
     * 根据条件查询通知历史
     * @param condition
     * @return
     */
    public List<NotifyHisBean> findByCondition(Condition condition, String dimension) {
        String resTypeId = "";
        List<String> dimensionList = new ArrayList<String>();
        if (!dimension.equals("")) {
            String[] array = dimension.split("[|]");
            for (String scope : array) {
                if (scope.split(",")[0].split("-")[0].equals("0")) {
                    resTypeId = scope.split(",")[1];
                } else {
                    dimensionList.add(scope.split(",")[1]);
                }
            }
        }
        return notifyDao.findByCondition(condition, resTypeId, dimensionList);
    }

    /**
     * 根据Id查询NotifyHisBean对象
     * 
     * @param id
     * @return
     */
    public NotifyHisBean findById(Long id) {
        return notifyDao.findById(id);
    }

}